<%--
  Created by IntelliJ IDEA.
  User: Acer
  Date: 2020/9/30
  Time: 16:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="rapid" uri="http://www.rapid-framework.org.cn/rapid" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<rapid:override name="head">
    <title>修改信息</title>
</rapid:override>

<rapid:override name="content">
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() +":" + request.getServerPort() + path +"/";
    %>


    <form class="layui-form" action="" style="width: 450px;margin: 10px auto">
        <div class="layui-form-item">
            <label class="layui-form-label">课程名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入课程名称" class="layui-input" id="name" value="${courseInfo.className}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人数限制</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required"  placeholder="请输入人数" autocomplete="off" class="layui-input" id="num" value="${courseInfo.classNum}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">学院限制</label>
            <div class="layui-input-block">
                <c:forEach items="${insList}" var="ins">
                    <input type="checkbox" name="ins" title="${ins.insName}" value="${ins.insId}"

                           <c:forEach items="${checkIns}" var="checkIns">
                                <c:if test="${ins.insId == checkIns}">
                                    checked
                                </c:if>
                            </c:forEach>
                    >
                </c:forEach>
            </div>
        </div>
        <div class="layui-input-block" >
            <button type="button" onclick="javascript:history.back(-1);" class="layui-btn layui-btn-lg">
                返回上一页
            </button>
            <button type="button" id="success" class="layui-btn layui-btn-danger layui-btn-lg">
                确认提交
            </button>
        </div>
    </form>

    <script src="<%=basePath%>/statics/js/jquery-3.3.1.js"></script>
    <script>
        $('#success').click(function () {
            /**
             * 将各种已知的信息通过表单方式传递给后台
             * @type {jQuery|string|undefined}
             */
            let name = $('#name').val();
            let num = $('#num').val();
            let ins = "";
            let cnt = 0;
            $("input[name = 'ins']:checked").each(function () {
                cnt ++;
                if(cnt === 1) {
                    ins = ins + $(this).attr('value');
                } else {
                    ins = ins + "," + $(this).attr("value");
                }
            })

            let content = name + "|" + num + "|" + ins;

            let myform = document.createElement("form");

            myform.id = 'form1';
            myform.name = "form1";

            document.body.appendChild(myform);

            let input = document.createElement("input");

            input.type = "text";
            input.name="content";
            input.value=encodeURIComponent(encodeURIComponent(content));

            myform.appendChild(input);
            myform.action="<%=basePath%>teacher/updateCourseSuccess?classId=${courseInfo.classId}&page="+1;
            myform.method='POST';

            myform.submit();
            document.body.removeChild(myform);
        })
    </script>
</rapid:override>
<%@include file="base.jsp"%>
